package cn.deschen.common.api;

/**
 * @Author hanbin_chen
 * @Description 封装API的响应状态码
 * @DateTime 2021/6/1
 * @Version 1.0.0
 */
public interface IResCode {

    Integer getCode();

    String getMessage();

    String FORMAT_MESSAGE = "%s: %s";

    /**
     * 补充参数说明<br/>
     * <p>格式</p>
     * <p>状态消息：补充内容</p>
     * @param msg 补充内容
     * @return
     */
    default IResCode extra(Object msg) {
        Integer code = this.getCode();
        String message = String.format(FORMAT_MESSAGE, this.getMessage(), msg);
        return new IResCode() {
            @Override
            public Integer getCode() {
                return code;
            }

            @Override
            public String getMessage() {
                return message;
            }
        };
    }

    /**
     * 消息参数拼接<br/>
     * <p>格式</p>
     * <p>状态消息%s</p>
     * @param msgs 消息参数
     * @return
     */
    default IResCode fillArgs(Object... msgs) {
        Integer code = this.getCode();
        String message = String.format(this.getMessage(), msgs);
        return new IResCode() {
            @Override
            public Integer getCode() {
                return code;
            }

            @Override
            public String getMessage() {
                return message;
            }
        };
    }


}
